package appcomp.graphtools;

import appcomp.entities.*;

import java.util.ArrayList;
import java.util.List;

public class GraphNodeWrapper {
	
	private final Operator coreOp;
	private ArrayList<GraphNodeWrapper> children;
	private ArrayList<GraphNodeWrapper> parents;
	private String flowSignature;
		
	public GraphNodeWrapper() {
		children = new ArrayList<GraphNodeWrapper>();
		parents = new ArrayList<GraphNodeWrapper>();
		coreOp = null;
		flowSignature = "NULL";
	}
	
	/**
	 * @param coreOp
	 */
	public GraphNodeWrapper(Operator coreOp) {
		this.coreOp = coreOp;
		children = new ArrayList<GraphNodeWrapper>();
		parents = new ArrayList<GraphNodeWrapper>();
		try{
			flowSignature = coreOp.getState().getFlowSig().getName();
		}
		catch(Exception e) {
			flowSignature = "NULL";
		}
	}
	/**
	 * @return the coreOp
	 */
	public Operator getCoreOp() {
		return coreOp;
	}
	/**
	 * @return the parents
	 */
	public ArrayList<GraphNodeWrapper> getParents() {
		return parents;
	}
	public void addParent(GraphNodeWrapper p) {
		parents.add(p);
	}
	/**
	 * @return the children
	 */
	public List<GraphNodeWrapper> getChildren() {
		return children;
	}
	public void addChild(GraphNodeWrapper c) {
		children.add(c);
	}
	/**
	 * @return the flowSignature
	 */
	public String getFlowSignature() {
		return flowSignature;
	}
	
	public void setFlowSignature(String fs) {
		this.flowSignature = fs;
	}
	
	public boolean hasChildren() {
		return !children.isEmpty();
	}
	
	public void printNode() {
		System.out.println("\t" + coreOp.getName() + ":" + flowSignature);
		for(GraphNodeWrapper n : children) {
			n.printNode();
		}
	}

	public boolean isInComposite() {
		return coreOp.isInComposite();
	}
	
	public void joinedComposite() {
		coreOp.joinedComposite();
	}
	
}
